#include "Compass.h"

Compass::Compass(){
    _compass = new LSM303();

    _compass->init();
    _compass->enableDefault();

    _lastHeading = _heading = 0;
    _headingChanged = true;
}

Compass::~Compass(){
    delete _compass;
}

void Compass::measureHeading(){
    _compass->readAcc();
    _compass->readMag();

    _heading = static_cast<uint16_t>(floor(_compass->heading()));

    if(_heading != _lastHeading){
        _headingChanged = true;
    }
    else{
        _headingChanged = false;
    }

    _lastHeading = _heading;
}

uint16_t Compass::getHeading(){
    return _heading;
}

bool Compass::headingChanged(){
    return _headingChanged;
}
